<?php
class MemcacheHelper {
	const DEFAULT_EXPIRE = 86400;

	public static $_memcache = null;

	public static function getInstance() {
		if (self::$_memcache === null) {
			self::$_memcache = new Memcache();
			// connect to memcached server
			self::$_memcache->connect(MEMCACHE_HOST, MEMCACHE_PORT);
		}
		return self::$_memcache;
	}
	public static function set($key, $value, $expire=null) {
		if ($expire === null) {
			$expire = self::DEFAULT_EXPIRE;
		}
		if (!$key) {
			//$key = "DEFAULT_MEMCACHE_KEY";
		}
		self::getInstance()->set($key, $value, 0, $expire);
	}
	public static function get($key) {
		if (!$key) {
			//$key = "DEFAULT_MEMCACHE_KEY";
		}
		return self::getInstance()->get($key);
	}
	public static function delete($key) {
		if (!$key) {
			//$key = "DEFAULT_MEMCACHE_KEY";
		}
		return self::getInstance()->delete($key);
	}
}
